
"""
	user 'MySQLdb' connect the mysql in pyhton eg.
	MySQLdb: http://sourceforge.net/projects/mysql-python/
	date: 14-7-15
"""
import MySQLdb

try:
	conn=MySQLdb.connect(host='localhost',user='root',passwd='meng',db='test',port=3306)
	cur = conn.cursor()
	#insert 
	sql = "insert into clazz values(%s,%s)"
	param = (1,"smark")
	n = cur.execute(sql,param)

	#update
	sql = "update clazz set cname=%s where cid =%s"
	param = ("smark-m",1)
	n = cur.execute(sql,param)

	#select
	n = cur.execute("select * from clazz")
	for row in cur.fetchall():
		print row
		

	cur.close()
	conn.commit()
	print str(n)+" row effect\n"

except Exception, e:
	print "connect to mysql faild:\n"
	print e